<template>
  <div>
    <van-nav-bar
        title="个人资料"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
    />


      <van-button type="danger" size="large" @click="logout">退出登录</van-button>

  </div>
</template>

<script>

export default {
  name: "logout",
  setup() {
    const onClickLeft = () => history.back();
      return {
        onClickLeft,
      };
  },
  methods:{
    logout(){
      const axios = require('axios');
      const config = {
        method: 'post',
        url: 'http://106.54.189.155:6768/user/logout',
        headers: {
        }
      };
      axios(config)
          .then(function (response) {
            console.log(JSON.stringify(response.data));
          })
          .catch(function (error) {
            console.log(error);
          });
      localStorage.clear();
      localStorage.removeItem("payload");
      setTimeout(() => {
        this.$router.push({
          path: '/login'
        }, () => {
        }, () => {
        });//退出登录后2秒后跳转至登录
      }, 2000)
      //加()=>{},()=>{} 可解决路由重复后台报错问题
    }
  }
}
</script>

<style scoped>

</style>